package com.jiapu.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jiapu.common.Result;
import com.jiapu.entity.Event;
import com.jiapu.entity.User;
import com.jiapu.mapper.EventMapper;
import com.jiapu.mapper.UserMapper;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    UserMapper userMapper;

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUser_id, user.getUser_id()).eq(User::getPassword, user.getPassword()));
        if(res == null){
            return Result.error("1","用户名或密码错误！");
        }
        userMapper.insert(user);
        return Result.success();
    }

    @PostMapping("/register")
    public Result register(@RequestBody User user){
        User res = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUser_id, user.getUser_id()));
        if(res != null){
            return Result.error("1","用户名重复");
        }
        userMapper.insert(user);
        return Result.success();
    }
}
